-
Notifications
You must be signed in to change notification settings - Fork 0
feat(api): add recipe CRUD with cookie authentication #57
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall! Approving, but I noticed a few things that might be worth considering now or in future work. None of these are blockers.
Frontend/API discrepancies and future integration
- Search: Explore and Cookbook currently support searching by ingredients and tags as well as title/description, while the API only searches title/description. I see that advanced search is planned for D3, which is fine. We should just keep this difference in mind during frontend integration, and ideally keep the query structure easy to extend when adding ingredient/tag search later.
- Create Recipe fields: The API requires difficulty and separate prepMinutes/cookMinutes, while the current Add Recipe form only has one cooking-time field and no difficulty selection. The documentation already suggests possible mappings/defaults, but be careful to not store potentially misleading values.
- Image uploads: The current form supports uploading/cropping images, but the API only accepts an image URL. I see that uploads are outside this PR's scope. We should decide how to handle this during integration (e.g. temporarily omitting images) and make sure the approach can accommodate proper image storage/uploading later without major changes to recipe CRUD.
- Sorting and pagination: Explore and Cookbook currently offer several sorting options, while the API only sorts by creation date (newest first). Advanced sorting is planned for D3, but we should be careful during integration since sorting locally after fetching a paginated result would only sort that page, not all recipes. When implementing sorting later, it should therefore happen in the backend before pagination.
Code and architecture suggestions
- GraphQL enums: Could be worth using enums for fixed values like RecipeDifficulty, RecipeVisibility, RecipeCategory, and CookbookScope instead of plain strings. This would improve type safety and keep frontend/backend values consistent, especially as we add more functionality.
- SQL query structure: Some of the query construction in recipeRepository.ts is a bit complex, particularly the cookbook scope conditions. Extracting named helpers and separating access/visibility logic from filtering could improve readability and make it easier to add more search/filter options in D3.
- Recipe list queries: The list queries currently fetch full recipe details, including ingredients and instructions, even when only summary data is needed for cards. Not urgent with our current dataset, but separating list-summary and detail queries could be useful as the application grows.
- Error handling: The repository currently throws GraphQLError directly. Not a big issue for our project right now, but separating domain errors (e.g. RecipeNotFoundError) from GraphQL-specific errors could make the database layer more independent and easier to maintain.
Overall, nice work! Most of these are just things to keep in mind for frontend integration or future improvements.
Addresses review feedback by introducing GraphQL enums for difficulty, visibility, category and cookbook scope, regenerating contracts, and separating SQL access rules from list filters. Adds enum contract tests and extends cookbook visibility coverage. Documents the upcoming frontend integration: explicit difficulty and prep/cook fields, temporary image-upload limitations, and controls that match current API search and sorting support. Frontend integration will follow in a separate branch. D3 will add ingredient/tag search and backend sorting before pagination. List/detail query optimization and domain-error separation remain future improvements. Validation: 235 tests and API/database tests passed, along with lint, type checks, contract generation checks and build. The full check command is blocked by an existing formatting issue in unchanged app.ts. |
Change
Added recipe CRUD, Save/Unsave and Cookbook operations with Zod validation, cookie authentication and owner-only editing/deletion.
Added GraphQL contracts and frontend documentation. Frontend integration comes in step 3.
Verification
All project checks, API/database tests and browser tests passed.
AI use
AI assisted with analyze, modelling, documentation and testing.